/*
 * Copyright 2007-2009 Perttu "celeron55" Ahola <celeron55@gmail.com>
 *
 * This file is part of jukumagic.
 *
 * jukumagic is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * jukumagic is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with jukumagic.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "strfnd.h"

unsigned int strfnd::getp()
{
	return p;
}
void strfnd::moveto(unsigned int place){
	p = place;
}
void strfnd::start(const std::string &niinq){
	tek = niinq;
	p=0;
}
void strfnd::start(const char *niinq){
	tek = niinq;
	p=0;
}
std::string strfnd::next(const std::string &plop){
	size_t n;
	std::string palautus;
	if (p < tek.size())
	{
		if ((n = tek.find(plop, p)) == std::string::npos || plop == "")
		{
			n = tek.size();
		}
		else
		{
		}
		palautus = tek.substr(p, n-p);
		p = n + plop.length();
	}
	return palautus;
}
bool strfnd::atend(){
	if(p>=tek.size()) return true;
	return false;
}
strfnd::strfnd(const std::string &s){
	start(s);
}
strfnd::strfnd(const char *s){
	start(s);
}

// wx version

unsigned int strfnd_wx::getp()
{
	return p;
}
void strfnd_wx::moveto(unsigned int place){
	p = place;
}
void strfnd_wx::start(const wxString &niinq){
	tek = niinq;
	p=0;
}
void strfnd_wx::start(const char *niinq){
	tek = wxString(niinq, wxConvUTF8);
	p=0;
}
wxString strfnd_wx::next(const wxString &plop){
	size_t n;
	wxString palautus;
	if (p < tek.size())
	{
		if ((n = tek.find(plop, p)) == wxString::npos || plop == _T(""))
		{
			n = tek.size();
		}
		else
		{
		}
		palautus = tek.substr(p, n-p);
		p = n + plop.length();
	}
	return palautus;
}
bool strfnd_wx::atend(){
	if(p>=tek.size()) return true;
	return false;
}
strfnd_wx::strfnd_wx(const wxString &s){
	start(s);
}
strfnd_wx::strfnd_wx(const char *s){
	start(s);
}

